home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / os / sprite.X11R3 / fileIO.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-09  |  2.3 KB  |  101 lines

  1. /*-
  2.  * fileIO.c --
  3.  *    functions for os-independent file I/O
  4.  *
  5.  * Copyright (c) 1987 by the Regents of the University of California
  6.  *
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * TODO:
  16.  *    - Snarf compressed-font stuff from 4.2bsd fileio.c
  17.  *
  18.  */
  19. #ifndef lint
  20. static char rcsid[] =
  21.     "$Header: fileIO.c,v 1.2 88/09/08 18:15:35 ouster Exp $ SPRITE (Berkeley)";
  22. #endif lint
  23.  
  24. #include    "spriteos.h"
  25. #include    <stdio.h>
  26.  
  27. /*-
  28.  *-----------------------------------------------------------------------
  29.  * FiOpenForRead --
  30.  *    Open a file for reading. The name needn't be null terminated.
  31.  *    We do it here if it ain't.
  32.  *
  33.  * Results:
  34.  *    An FID (FILE *)
  35.  *
  36.  * Side Effects:
  37.  *
  38.  *-----------------------------------------------------------------------
  39.  */
  40. FID
  41. FiOpenForRead (nameLen, name)
  42.     int              nameLen;      /* Length of the name */
  43.     char          *name;        /* The name itself */
  44. {
  45.     FILE *      stream;
  46.     char          *null_t_name = name;
  47.  
  48.     if (name[nameLen-1] != '\0') {
  49.     null_t_name = (char *)ALLOCATE_LOCAL (nameLen+1);
  50.     strncpy (null_t_name, name, nameLen);
  51.     null_t_name[nameLen] = '\0';
  52.     }
  53.  
  54.     stream = fopen (null_t_name, "r");
  55.  
  56.     if (null_t_name != name) {
  57.     DEALLOCATE_LOCAL(null_t_name);
  58.     }
  59.     return ((FID) stream);
  60. }
  61.  
  62. /*-
  63.  *-----------------------------------------------------------------------
  64.  * FiRead --
  65.  *    Read from an open stream
  66.  *
  67.  * Results:
  68.  *
  69.  * Side Effects:
  70.  *
  71.  *-----------------------------------------------------------------------
  72.  */
  73. int
  74. FiRead (buf, itemSize, numItems, fid)
  75.     char          *buf;
  76.     unsigned      itemSize;
  77.     unsigned      numItems;
  78.     FID              fid;
  79. {
  80.     return fread (buf, itemSize, numItems, (FILE *) fid);
  81. }
  82.  
  83. /*-
  84.  *-----------------------------------------------------------------------
  85.  * FiClose --
  86.  *    Close an open stream
  87.  *
  88.  * Results:
  89.  *
  90.  * Side Effects:
  91.  *
  92.  *-----------------------------------------------------------------------
  93.  */
  94. int
  95. FiClose (fid)
  96.     FID        fid;
  97. {
  98.     fclose ((FILE *)fid);
  99.     return (0);
  100. }
  101.